home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / DB_CLIPP / 2510.ZIP / TRSOURCE.EXE / EOQ.C < prev    next >
C/C++ Source or Header  |  1990-10-22  |  1KB  |  51 lines

  1. /*********
  2. *
  3. *  EOQ.C
  4. *
  5. *  by Ralph Davis
  6. *  modified by Tom Rettig
  7. *
  8. * Placed in the public domain by Tom Rettig Associates, 10/22/1990.
  9. *
  10. *********/
  11.  
  12. /* EOQ:  Economic Order Quantity
  13.  
  14.          Computes economic quantity of inventory item to order.
  15.  
  16.          SYNTAX:  EOQ(balance, demand, cost, price, overhead)
  17.  
  18.                   where balance  = amount on hand
  19.                         demand   = average demand per order period
  20.                         cost     = cost of placing an order
  21.                         price    = unit purchase price
  22.                         overhead = percentage cost of purchase price
  23.                                    for inventory overhead
  24.  
  25.          RETURNS:  0 if balance >= 2 * demand,
  26.                    otherwise amount to order as a long integer
  27. */
  28.  
  29. #include "trlib.h"
  30.  
  31. TRTYPE eoq()
  32. {
  33.    if ( PCOUNT==5 && ISNUM(1) && ISNUM(2) &&
  34.                      ISNUM(3) && ISNUM(4) && ISNUM(5) )
  35.    {
  36.       double balance   = _parnd(1);
  37.       double demand    = _parnd(2);
  38.       double ordercost = _parnd(3);
  39.       double purchase  = _parnd(4);
  40.       double overhead  = _parnd(5);
  41.  
  42.       if (balance < (2.0 * demand))
  43.          _retnl((long)(_tr_sqrt((2.0 * demand * ordercost) 
  44.                                   / (purchase * overhead))));
  45.       else
  46.          _retnl( (long)ERROR );
  47.    }
  48.    else
  49.       _retnl( (long)ERROR );
  50. }
  51.